package com.team.employment.web.admin.service.impl;


import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.team.employment.model.entity.CompanyInfo;
import com.team.employment.model.entity.CompanyStatutory;
import com.team.employment.web.admin.mapper.CompanyInfoMapper;
import com.team.employment.web.admin.service.CompanyStatutoryService;

import com.team.employment.web.admin.mapper.CompanyStatutoryMapper;
import com.team.employment.web.admin.vo.StatutoryCompanyVo;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.ArrayList;
import java.util.List;

/**
* @author 陈钰儿
* @description 针对表【company_statutory(公司法定人关联表)】的数据库操作Service实现
* @createDate 2025-04-11 15:49:26
*/
@Service
public class CompanyStatutoryServiceImpl extends ServiceImpl<CompanyStatutoryMapper, CompanyStatutory>
    implements CompanyStatutoryService{

    @Autowired
    private CompanyInfoMapper companyInfoMapper;

    @Autowired
    private CompanyStatutoryMapper companyStatutoryMapper;

    @Override
    public List<StatutoryCompanyVo> getCompanyInfoByStatutoryId(Long id) {
        LambdaQueryWrapper<CompanyStatutory> lambdaQueryWrapper = new LambdaQueryWrapper<>();
        lambdaQueryWrapper.eq(CompanyStatutory::getStatutoryId,id);
        List<CompanyStatutory> companyStatutorys = companyStatutoryMapper.selectList(lambdaQueryWrapper);

        List<Long> companyIds  = new ArrayList<>();
        companyStatutorys.forEach(companyStatutory ->{
            companyIds.add(companyStatutory.getCompanyId());
        } );

        LambdaQueryWrapper<CompanyInfo> wrapper = new LambdaQueryWrapper<>();
        wrapper.in(CompanyInfo::getId,companyIds);
        List<CompanyInfo> companyInfos = companyInfoMapper.selectList(wrapper);

        List<StatutoryCompanyVo> list = new ArrayList<>();
        companyInfos.forEach(companyInfo -> {
            StatutoryCompanyVo companyVo = StatutoryCompanyVo.builder().companyName(companyInfo.getName())
                    .companyStatus(companyInfo.getCompanyStatus())
                    .build();
            list.add(companyVo);
        });

        return list;
    }

}




